/*
 * AIEngine a new generation network intrusion detection system.
 *
 * Copyright (C) 2013-2023  Luis Campo Giralte
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 *
 * Written by Luis Campo Giralte <luis.camp0.2009@gmail.com> 
 *
 */
#ifndef SRC_OUTPUTMANAGER_H_
#define SRC_OUTPUTMANAGER_H_

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <iostream>
#include <fstream> 
#include <sstream> 

namespace aiengine {

template <class T>
class SingletonOutputManager
{
public:
        template <typename... Args>

        static T* getInstance()
        {
                if(!outputMngInstance_)
                {
                        outputMngInstance_ = new T();

			outputMngInstance_->setOutput(std::cout);
                }
                return outputMngInstance_;
        }

        static void destroyInstance()
        {
                delete outputMngInstance_;
                outputMngInstance_ = nullptr;
        }

private:
        static T* outputMngInstance_;
};

template <class T> T*  SingletonOutputManager<T>::outputMngInstance_ = nullptr;
class OutputManager: public SingletonOutputManager<OutputManager>
{
public:

	std::basic_ostream<char> &out() { return *active_out_; }

	void setOutput(std::ostream &out) { active_out_ = &out; }

	friend class SingletonOutputManager<OutputManager>;
private:
	std::basic_ostream<char> *active_out_;
};

} // namespace aiengine

#endif  // SRC_OUTPUTMANAGER_H_
